package com.mzz.behavior.fatherandson.template;

/**
 * 定义类JSONFormatter继承自Formatter，里面加入处理JSON格式的具体逻辑
 */
public class JSONFormatter extends AbstractFormatter {

    @Override
    protected String format(Book book) {

        String result = "";
        result += "{\n";
        result += "\"book_name\" : \"" + book.getBookName() + "\",\n";
        result += "\"pages\" : \"" + book.getPages() + "\",\n";
        result += "\"price\" : \"" + book.getPrice() + "\",\n";
        result += "\"author\" : \"" + book.getAuthor() + "\",\n";
        result += "\"isbn\" : \"" + book.getIsbn() + "\",\n";
        result += "}";
        return result;
    }
}
